import Vue from 'vue';
import Router from 'vue-router';
const _import = require('./_import_' + process.env.NODE_ENV);
// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow.so only in production use Lazy Loading

/* layout */
import Layout from '../views/layout/Layout';

/* login */
const Login = _import('login/index');

/* dashboard */
const dashboard = _import('dashboard/index');

/* error page */
const Err404 = _import('404');

/* demo page */
const Form = _import('page/form');
const Table = _import('table/index');

const InfoIndex = _import('page/info/index');
const InfoEdit = _import('page/info/add');

const CityAdd = _import('page/setting/cityAdd');
const CityIndex = _import('page/setting/city');
const SiteIndex = _import('page/setting/site');
const SiteAdd = _import('page/setting/siteAdd');
// const AdsSetting = _import('page/setting/ads');

Vue.use(Router);

 /**
  * icon : the icon show in the sidebar
  * hidden : if `hidden:true` will not show in the sidebar
  * redirect : if `redirect:noredirect` will not redirct in the levelbar
  * noDropdown : if `noDropdown:true` will not has submenu in the sidebar
  * meta : `{ role: ['admin'] }`  will control the page role
  **/
export const constantRouterMap = [
  { path: '/login', component: Login, hidden: true },
  { path: '/404', component: Err404, hidden: true },



]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
});

export const asyncRouterMap = [

  {
    path: '/',
    component: Layout,
    redirect: '/info/index',
    name: 'Home',
    icon: 'weibiaoti1fuzhi04',
    hidden: true
  },
  {
    path: '/info',
    component: Layout,
    redirect: 'noredirect',
    icon: 'weibiaoti1fuzhi04',
    noDropdown: true,
    children: [
      { path: 'index', component: InfoIndex, name: '信息管理' },
    ]
  },
  {
    path: '/info',
    component: Layout,
    redirect: 'noredirect',
    name: '信息发布',
    icon: 'weibiaoti1fuzhi04',
    noDropdown: true,
    children: [
      { path: 'add', component: InfoEdit, name: '信息添加' },
      { path: 'edit/:id', component: InfoEdit, name: '编辑信息', hidden: true},
    ]
  },
  {
    path: '/member',
    component: Layout,
    redirect: 'noredirect',
    name: '用户管理',
    icon: 'weibiaoti1fuzhi04',
    children: [

      { path: 'staffs', component: _import('page/user/staffs'), name: '员工管理' },
      { path: 'staffs/add', component: _import('page/user/staff'), name: '员工添加',hidden: true },
      { path: 'staffs/:id', component: _import('page/user/staff'), name: '员工编辑',hidden: true },
    ]
  },
  {
    path: '/setting',
    component: Layout,
    redirect: 'noredirect',
    name: '系统管理',
    icon: 'xitong',
    roles: 'root',
    children: [
        { path: 'users', component: _import('page/user/users'), name: '会员管理', roles: 'root'},
      { path: 'city', component: CityIndex, name: '城市管理', icon: 'zonghe', roles: 'root'},
      { path: 'city/add', component: CityAdd, name: '编辑站点', hidden: true},
      { path: 'city/:id', component: CityAdd, name: '编辑站点', hidden: true, meta: { isEdit: true }},
      { path: 'site', component: SiteIndex, name: '站点管理', icon: 'zonghe' },
      { path: 'site/add', component: SiteAdd, name: '添加站点', hidden: true, roles: 'root'},
      { path: 'site/edit/:id', component: SiteAdd, name: '编辑站点', hidden: true},
    ]
  },
  // {
  //   path: '/info',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   name: '系统管理',
  //   icon: 'zujian',
  //   children: [
  //     { path: '/site', component: Form, name: '站点管理', icon: 'zonghe' },
  //     { path: '/city', component: Form, name: '城市管理', icon: 'zonghe' }
  //   ]
  // },
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   name: 'Example',
  //   icon: 'zujian',
  //   children: [
  //     { path: 'guanli', component: InfoIndex, name: '信息管理', icon: 'zonghe' },
  //     { path: 'index', component: Form, name: 'Form', icon: 'zonghe' }
  //   ]
  // },
  //
  // {
  //   path: '/table',
  //   component: Layout,
  //   redirect: '/table/index',
  //   name: 'Table',
  //   icon: 'tubiaoleixingzhengchang',
  //   noDropdown: true,
  //   children: [{ path: 'index', component: Table, name: 'Table', meta: { role: ['admin'] } }]
  // },

  { path: '*', redirect: '/404', hidden: true }
];
